#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "canthread.h"
#include "rechargethread.h"
#include "qcustomplot.h"
#include "mydata.h"
#include <QThread>
#include <QThreadPool>
#include <QTimer>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void Init();

    QThread  *thread_1 = NULL;
    RechargeThread *recharge = NULL;

    QString FileabsolutePath = "./InfyPowerControl.exe";

    void timerEvent(QTimerEvent *event);

    void System_ModuleNum(QString da1);

    void System_V_A(QString da1);//系统电压电流
    void Module1_V_A(QString da1);//模块1电压电流
    void Module2_V_A(QString da1);//模块2电压电流
    void Module3_V_A(QString da1);//模块3电压电流
    void Module4_V_A(QString da1);//模块4电压电流
    void Module1_state(QString da1);//模块1状态
    void Module2_state(QString da1);//模块2状态
    void Module3_state(QString da1);//模块3状态
    void Module4_state(QString da1);//模块4状态
    void CEG1_View(QString da1);
    void CEG2_View(QString da1);
    void CEG3_View(QString da1);
    void CEG4_View(QString da1);

    void customPlotModule_V_A();

    void System_set(QString id1,QString da1);
    void Module_set_Series(QString da1);
    void Module1_set(QString da1);
    void Module2_set(QString da1);
    void Module3_set(QString da1);
    void Module4_set(QString da1);
    void module1_walkin(QString id,QString da1);
    void module2_walkin(QString da1);
    void module3_walkin(QString da1);
    void module4_walkin(QString da1);

    void module1_start(QString da1);
    void module2_start(QString da1);
    void module3_start(QString da1);
    void module4_start(QString da1);

    QString bug1_1 = "0";
    QString bug1_2 = "0";
    QString bug1_3 = "0";
    QString bug1_4 = "0";
    QString bug2_1 = "0";
    QString bug2_2 = "0";
    QString bug2_3 = "0";
    QString bug2_4 = "0";
    QString bug3_1 = "0";
    QString bug3_2 = "0";
    QString bug3_3 = "0";
    QString bug3_4 = "0";
    QString bug4_1 = "0";
    QString bug4_2 = "0";
    QString bug4_3 = "0";
    QString bug4_4 = "0";
    QString bug5_1 = "0";
    QString bug5_2 = "0";
    QString bug5_3 = "0";
    QString bug5_4 = "0";
    QString bug6_1 = "0";
    QString bug6_2 = "0";
    QString bug6_3 = "0";
    QString bug6_4 = "0";
    QString bug7_1 = "0";
    QString bug7_2 = "0";
    QString bug7_3 = "0";
    QString bug7_4 = "0";
    QString bug8_1 = "0";
    QString bug8_2 = "0";
    QString bug8_3 = "0";
    QString bug8_4 = "0";
    QString bug9_1 = "0";
    QString bug9_2 = "0";
    QString bug9_3 = "0";
    QString bug9_4 = "0";
    QString bug10_1 ="0";
    QString bug10_2 ="0";
    QString bug10_3 ="0";
    QString bug10_4 ="0";
    QString bug11_1 ="0";
    QString bug11_2 ="0";
    QString bug11_3 ="0";
    QString bug11_4 ="0";
    QString bug12_1 ="0";
    QString bug12_2 ="0";
    QString bug12_3 ="0";
    QString bug12_4 ="0";
    QString bug13_1 ="0";
    QString bug13_2 ="0";
    QString bug13_3 ="0";
    QString bug13_4 ="0";
    QString bug14_1 ="0";
    QString bug14_2 ="0";
    QString bug14_3 ="0";
    QString bug14_4 ="0";
    QString bug15_1 ="0";
    QString bug15_2 ="0";
    QString bug15_3 ="0";
    QString bug15_4 ="0";
    QString bug16_1 ="0";
    QString bug16_2 ="0";
    QString bug16_3 ="0";
    QString bug16_4 ="0";
    QString BUG1 = "0000";
    QString BUG2 = "0000";
    QString BUG3 = "0000";
    QString BUG4 = "0000";
    QString BUG5 = "0000";
    QString BUG6 = "0000";
    QString BUG7 = "0000";
    QString BUG8 = "0000";
    QString BUG9 = "0000";
    QString BUG10 = "0000";
    QString BUG11 = "0000";
    QString BUG12 = "0000";
    QString BUG13 = "0000";
    QString BUG14 = "0000";
    QString BUG15 = "0000";
    QString BUG16 = "0000";
    QString BUG_all = "000000000000000000000000000000000000000000000000000000000000";

    void Bug1(QString a1);
    void Bug2(QString a1);
    void Bug3(QString a1);
    void Bug4(QString a1);
    void Bug5(QString a1);
    void Bug6(QString a1);
    void Bug7(QString a1);
    void Bug8(QString a1);
    void Bug9(QString a1);
    void Bug10(QString a1);
    void Bug11(QString a1);
    void Bug12(QString a1);
    void Bug13(QString a1);
    void Bug14(QString a1);
    void Bug15(QString a1);
    void Bug_All(QString a1);
    void Signal_open();
    void Signal_stop();
    void Signal_receive();

    float V1 = 0;
    float V2 = 0;
    float V3 = 0;
    float V4 = 0;
    float V_sys = 0;
    float sys_vol = 0;
    float sys_cur = 0;

    QString star1 = "11";
    QString star2 = "11";
    QString star3 = "11";
    QString star4 = "11";
    QString Star = "11111111";

    float A1 = 0;
    float A2 = 0;
    float A3 = 0;
    float A4 = 0;
    float A_sys = 0;

    int set1 = 0;
    int set2 = 0;
    int set3 = 0;
    int set4 = 0;
    int sys_set = 0;
    int sys_num = 0;

    QString Data_set = "0000000000000000";

    void SendData_go();//设置系统各模块为拨号模式
    void SendData_group();//设置系统各模块组号
    void Vist_System_VA();//询问系统电压电流
    void Vist_Module_VA();//询问模块电压电流
    void Vist__VA1();//询问模块1电压电流
    void Vist_System_state();//询问系统各模块状态信息
    void Vist_state1();
    void Vist_System_module_Num();//询问系统各模块数量
    void Vist_CEG1();
    void Vist_CEG2();
    void Vist_CEG3();
    void Vist_CEG4();

private slots:
    void on_btnStart_clicked();

    void on_btnStop_clicked();

    void on_btnCan_clicked();

    void on_btnSendGo_clicked();

    void on_btnSet_clicked();

    void on_btnLightGreen_clicked();


    void on_btnWalkin_start_clicked();

    void on_btnWalkin_stop_clicked();

    void mouseWheel();

    //游标函数
    void mouseMoveEvent(QMouseEvent *event);

    //图例选中曲线函数
    void selectionChanged();

    void handleRightClick(QMouseEvent *event);

    void when_legendDoubleClick (QCPLegend *legend, QCPAbstractLegendItem *legendItem, QMouseEvent *event);

    void on_btnCAN_clicked();

    void on_cc1state_le_2_cursorPositionChanged(int arg1, int arg2);

    void on_btnfile_clicked();

    //文件路径判断函数
    bool isDirExist(QString fullPath);


    void on_btnMPPT_clicked();

    void on_btnSRHY_clicked();

signals:
    void SIGtocansen(unsigned int ID, std::vector<int> vec);
    void SIGtocancon();                                     //启动CAN按钮发出的信号
    void SIGtocansto();                                     //关闭CAN按钮发出的信号
    void sig_module1_bug(QString da);
    void sig_module2_bug(QString da);
    void sig_module3_bug(QString da);
    void sig_module4_bug(QString da);

    void sig_bug1(QString a1);
    void sig_bug2(QString a1);
    void sig_bug3(QString a1);
    void sig_bug4(QString a1);
    void sig_bug5(QString a1);
    void sig_bug6(QString a1);
    void sig_bug7(QString a1);
    void sig_bug8(QString a1);
    void sig_bug9(QString a1);
    void sig_bug10(QString a1);
    void sig_bug11(QString a1);
    void sig_bug12(QString a1);
    void sig_bug13(QString a1);
    void sig_bug14(QString a1);
    void sig_bug15(QString a1);
    void sig_bugAll(QString a1);

private:
    Ui::MainWindow *ui;

    QTimer *timer_setGroup;
    QTimer *timer_setmodule;
    QTimer m_Timer;
    QTimer Timer;
    QTimer *timer;

    int refreshTimer; //刷新图像的定时器
    int sampleTimer; //模拟采样的定时器

    QCustomPlot *plot;
    QCPItemTracer *tracer;  //游标定义
};
#endif // MAINWINDOW_H
